package com.example.config;

import com.alibaba.fastjson.JSONObject;
import com.example.entity.DetailsLogs;
import com.example.service.DetailsLogsService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: tobed
 * @date: 2022/11/11
 * @time: 13:29
 */
@Component
public class LogConsumer {

    @Autowired
    DetailsLogsService detailsLogsService;

    @RabbitListener(queues = QueueBean.INSERT_QUEUE_NAME)
    public void INSERT_QUEUE_NAME(Message message, Channel channel){
        DetailsLogs detailsLogs = JSONObject.parseObject(new String(message.getBody()), DetailsLogs.class);
        detailsLogsService.insertLog(detailsLogs);
    }

    @RabbitListener(queues = QueueBean.Update_QUEUE_NAME)
    public void Update_QUEUE_NAME(Message message, Channel channel){
        DetailsLogs detailsLogs = JSONObject.parseObject(new String(message.getBody()), DetailsLogs.class);
        detailsLogsService.updateLog(detailsLogs);
    }

    @RabbitListener(queues = QueueBean.Delete_QUEUE_NAME)
    public void Delete_QUEUE_NAME(Message message, Channel channel){
        DetailsLogs detailsLogs = JSONObject.parseObject(new String(message.getBody()), DetailsLogs.class);
        detailsLogsService.deleteLog(detailsLogs);
    }

}
